#pragma once
#include<json/json.h>

#include<string>
#include<iostream>
#include<vector>
#include<memory>
#include<sstream>

bool Serialize(const Json::Value& root,std::string& dest)
{
    Json::StreamWriterBuilder swb;
    std::unique_ptr<Json::StreamWriter> sw(swb.newStreamWriter());
    std::stringstream strem;
    int ret=sw->write(root,&strem);
    if(ret!=0)
    return false;
    dest=strem.str();
    return true;
}
bool UnSerialize(Json::Value& root,const std::string& src)
{
    Json::CharReaderBuilder crb;
    std::unique_ptr<Json::CharReader> cr(crb.newCharReader());
    std::string err;
    bool ret=cr->parse(src.c_str(),src.c_str()+src.size(),&root,&err);
    if(ret==false)
    {
        std::cout<<"反序列化失败"<<err<<std::endl;
        return false;
    }
    return true;
}